#include "backwidget.h"
#include "xitemwidget.h"

#define  HEILINE 24

BackWidget::BackWidget(QWidget *parent) :
    QWidget(parent)  
{
	//this->findChild()
 
}

BackWidget::~BackWidget()
{

}

void BackWidget::paintEvent(QPaintEvent *event)
{ //170 80

	QList<XItemWidget *> widgets = this->findChildren<XItemWidget *>();

	for each (XItemWidget* var in widgets)
	{
		//pstart.push_back(var->pos());
		pstart.push_back(QPoint(var->pos().x() + 85, var->pos().y()));

		QPoint end = QPoint(var->pos().x() + 85, var->pos().y() + var->height());
		pstart.push_back(end);
		//pend.push_back()
	}	
	QPainter painter(this);
	//painter.setBrush();
	painter.drawImage(rect(),QImage(":/image/timg.png"));
	QPen pen;
	pen.setColor(Qt::white);
	pen.setWidth(1);
	painter.setPen(pen);
	painter.setBrush(QColor(250, 240, 240));

	for (int i = 1; i < pstart.size()-1; i += 2)
	{
		if (pstart.at(i).y() < pstart.at(i + 1).y())
		{
			painter.drawLine(pstart.at(i), pstart.at(i + 1));

			

		}		
		else
		{

			//void QPainter::drawLines(const QVector<QPointF> &pointPairs)
			QVector<QPointF> lines;
			lines.push_back(pstart.at(i));
			lines.push_back(QPointF(pstart.at(i).x(), pstart.at(i).y() + HEILINE));


			lines.push_back(QPointF(pstart.at(i).x(), pstart.at(i).y() + HEILINE));
			lines.push_back(QPointF(((pstart.at(i).x() + pstart.at(i + 1).x()) / 2), pstart.at(i).y() + HEILINE));

			lines.push_back(QPointF(((pstart.at(i).x() + pstart.at(i + 1).x()) / 2), pstart.at(i).y() + HEILINE));
			lines.push_back(QPointF(((pstart.at(i).x() + pstart.at(i + 1).x()) / 2), pstart.at(i + 1).y() - HEILINE));

			lines.push_back(QPointF(((pstart.at(i).x() + pstart.at(i + 1).x()) / 2), pstart.at(i + 1).y() - HEILINE));
			lines.push_back(QPointF(pstart.at(i + 1).x(), pstart.at(i + 1).y() - HEILINE));

			lines.push_back(QPointF(pstart.at(i + 1).x(), pstart.at(i + 1).y() - HEILINE));
			lines.push_back(pstart.at(i + 1));
			painter.drawLines(lines);

		}

		QPointF points[3] = {
			QPointF(pstart.at(i + 1).x() - 8, pstart.at(i + 1).y() - 8),
			QPointF(pstart.at(i + 1).x() + 8, pstart.at(i + 1).y() - 8),
			QPointF(pstart.at(i + 1).x(), pstart.at(i + 1).y())
		};
		painter.drawPolygon(points, 3);

	}

	pstart.clear();
	//if (pstart.y() < pend.y())
	//{
	//	painter.drawLine(pstart, pend);
	//}	
	//else
	//{
	//	QPolygonF pointfs;
	//	pointfs.push_back(pstart);
	//	//pmid = QPoint()

	//	painter.drawPoints(pointfs);
	//}
	



}
